package com.srxz.mobilepharmacy.repository;

import com.srxz.mobilepharmacy.entity.procedure.MrPrfn;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.query.Procedure;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.math.BigInteger;

@Repository
public interface MrPrfnRepository extends CrudRepository<MrPrfn, Integer> {
    /**
     * 获取最新单据号
     * @param aid 机构编号
     * @param mrn 药房编号
     * @param typ 1
     * @return prf 单据号
     */
    @Query(value = "EXEC " +
            "  [dbo].[mr_prfn_new] " +
            "  @aid = ?1, " +
            "  @mrn = ?2, " +
            "  @typ = ?3 ", nativeQuery = true)
    BigInteger mrprfnnew(@Param("aid") BigInteger aid, @Param("mrn") Integer mrn, @Param("typ") Integer typ);

    /**
     * 保存单据
     * @param aid
     * @param mrn
     * @param typ
     * @return
     */
    @Query(value = "EXEC " +
            "  [dbo].[mr_prfn_save] " +
            "  @aid = ?1, " +
            "  @mrn = ?2, " +
            "  @typ = ?3, " +
            "  @oppo = ?4, " +
            "  @oprf = ?5, " +
            "  @note = ?6, " +
            "  @tmoney = ?7, " +
            "  @pfs = ?8, " +
            "  @opm = ?9, " +
            "  @opt = ?10, " +
            "  @hid = ?11, " +
            "  @did = ?12, " +
            "  @oopn = ?13, " +
            "  @st = ?14 ", nativeQuery = true)
    BigInteger mrprfnsave(@Param("aid") BigInteger aid, @Param("mrn") Integer mrn, @Param("typ") Integer typ,
                          @Param("oppo") Integer oppo, @Param("oprf") Integer oprf, @Param("note") String note,
                          @Param("tmoney") Double tmoney, @Param("pfs") Integer pfs, @Param("opm") String opm,
                          @Param("opt") String opt, @Param("hid") BigInteger hid, @Param("did") Double did,
                          @Param("oopn") BigInteger oopn, @Param("st") Integer st);

    /**
     * 保存明细-盘亏
     * @param aid
     * @param mrn
     * @param typ
     * @param pn
     * @param mid
     * @param attr
     * @param bn
     * @param vdate
     * @param quan
     * @param pri
     * @param prr
     * @param pro
     * @return
     */
    @Procedure(name = "mrstkexpsave")
    void mrstkexpsave(@Param("aid") BigInteger aid, @Param("mrn") Integer mrn, @Param("typ") Integer typ,
                            @Param("pn") Integer pn, @Param("mid") Integer mid, @Param("attr") Integer attr,
                            @Param("bn") String bn, @Param("vdate") Integer vdate, @Param("quan") BigDecimal quan,
                            @Param("pri") BigDecimal pri, @Param("prr") BigDecimal prr, @Param("pro") BigDecimal pro,
                      @Param("opt") String opt);

    /**
     * 保存明细-盘盈
     * @param aid
     * @param mrn
     * @param pn
     * @param mid
     * @param bn
     * @param nd
     * @param pri
     * @param prr
     * @param vdate
     * @param opitm
     */
    @Procedure(name = "mrstkimpsave")
    void mrstkimpsave(@Param("aid") BigInteger aid, @Param("mrn") Integer mrn,
                      @Param("pn") Integer pn, @Param("mid") Integer mid,
                      @Param("bn") String bn, @Param("nd") BigDecimal nd ,
                      @Param("pri") BigDecimal pri, @Param("prr") BigDecimal prr, @Param("vdate") Integer vdate,
                      @Param("opitm") String opitm);

    /**
     * 确认执行出库操作--盘亏
     * @param aid
     * @param pn
     * @param op
     * @param opt
     */
    @Procedure(name = "mrstkexpe")
    void mrstkexpe(@Param("aid") BigInteger aid, @Param("pn") Integer pn, @Param("op") String op, @Param("opt") String opt);

    /**
     * 确认执行出库操作--盘盈
     * @param aid
     * @param pn
     * @param op
     * @param opt
     */
    @Procedure(name = "mrstkimpe")
    void mrstkimpe(@Param("aid") BigInteger aid, @Param("pn") Integer pn, @Param("op") String op, @Param("opt") String opt);
}
